package com.msb.provider.controller;

import com.alibaba.fastjson2.JSONObject;
import com.msb.provider.service.HealthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author DreamAndLove
 * @date 2024/09/02 14:50
 * @description
 */
@RestController
public class HelloController {

    @Autowired
    private HealthService healthService;

    @Value("${server.port}")
    private String port;
    @GetMapping("/sayHello")
    public String sayHello() {
        return "hello, the port is:" + port ;
    }

    @GetMapping("/health/{status}")
    public String health(@PathVariable("status")Boolean status) {
        healthService.setStatus(status);
        return status + "";
    }

    @GetMapping("/personInfo")
    public JSONObject personInfo(@RequestParam("name")String name,
                                 @RequestParam("addr")String addr) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", name);
        jsonObject.put("address", addr);
        return jsonObject;
    }
}
